﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using eschoolBO;

namespace ESCHOOL.admin
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        bannerslide bs = new bannerslide();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnupdate.Visible = false;
                DataTable dt = bs.GetRecords(-99,"","","Top Banner","", false, " and ");
                string f = dt.Rows[0]["isactive"].ToString();
                GridView1.DataSource = dt;
                GridView1.DataBind();

                DataTable dt1 = bs.GetRecords(-99, "", "", "Slideshow", "", false, " and ");
                string g = dt.Rows[0]["isactive"].ToString();
                GridView2.DataSource = dt1;
                GridView2.DataBind();
            }

        }
        public bool getactive(string f)
        {
            
            if (f == "True")
            {
                return true;
            }
            else
            {
               return false;
            }
         
        }
        public bool getactive1(string g)
        {

            if (g == "True")
            {
                return true;
            }
            else
            {
                return false;
            }

        }
            
        
        protected void btnedit_Command(object sender, CommandEventArgs e)
        {
            btnupdate.Visible = true; btninsert.Visible = false;
            DataTable dt = bs.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", "Top Banner", "", false, " and ");
            tbid.Text = dt.Rows[0]["b_id"].ToString();
            tbimage.Text = dt.Rows[0]["b_image"].ToString();
            tbdescription.Text = dt.Rows[0]["b_description"].ToString();
            ddplace.SelectedValue = dt.Rows[0]["b_place"].ToString();
            RadioButtonList1.SelectedValue = dt.Rows[0]["isactive"].ToString();

        }

        protected void btndelete_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                DataTable dt = bs.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", "Top Banner", "", false, " and ");
                bs.b_id = Convert.ToInt64(dt.Rows[0]["b_id"].ToString());
                bs.b_image = dt.Rows[0]["b_image"].ToString();
                bs.b_description = dt.Rows[0]["b_description"].ToString();
                bs.b_place = dt.Rows[0]["b_place"].ToString();
                bs.isactive = dt.Rows[0]["isactive"].ToString();
                bs.isdeleted = true;
                bs.SaveRecords();
                Response.Redirect("~/admin/Banner.aspx");
            }
        }

        protected void checkactive_CheckedChanged(object sender, EventArgs e)
        {
           
        }

        protected void btnedit_Command1(object sender, CommandEventArgs e)
        {
            btnupdate.Visible = true; btninsert.Visible = false;
            DataTable dt = bs.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", "Slideshow", "", false, " and ");
            tbid.Text = dt.Rows[0]["b_id"].ToString();
            tbimage.Text = dt.Rows[0]["b_image"].ToString();
            tbdescription.Text = dt.Rows[0]["b_description"].ToString();
            ddplace.SelectedValue = dt.Rows[0]["b_place"].ToString();
            RadioButtonList1.SelectedValue = dt.Rows[0]["isactive"].ToString();
        }

        protected void btndelete_Command1(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                DataTable dt = bs.GetRecords(Convert.ToInt64(e.CommandArgument), "", "", "Slideshow", "", false, " and ");
                bs.b_id = Convert.ToInt64(dt.Rows[0]["b_id"].ToString());
                bs.b_image = dt.Rows[0]["b_image"].ToString();
                bs.b_description = dt.Rows[0]["b_description"].ToString();
                bs.b_place = dt.Rows[0]["b_place"].ToString();
                bs.isactive = dt.Rows[0]["isactive"].ToString();
                bs.isdeleted = true;
                bs.SaveRecords();
                Response.Redirect("~/admin/Banner.aspx");
            }
        }

        protected void btninsert_Click(object sender, EventArgs e)
        {
            bs.b_id = -99;
            if(FileUpload1.HasFile)
                FileUpload1.PostedFile.SaveAs(Server.MapPath("~/admin/banner/"+FileUpload1.FileName));
            bs.b_image = FileUpload1.FileName;
            bs.b_description = tbdescription.Text;
            bs.b_place = ddplace.SelectedValue.ToString();
            bs.isactive=  RadioButtonList1.SelectedValue.ToString();
            bs.isdeleted = false;
            bs.SaveRecords();
            Response.Redirect("~/admin/Banner.aspx");
        }
    

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }

        protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
        
        }

        protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
        {
        
        }

        protected void btnupdate_Click(object sender, EventArgs e)
        {
            bs.b_id = Convert.ToInt64(tbid.Text);
            if (FileUpload1.HasFile)
            {
                FileUpload1.PostedFile.SaveAs(Server.MapPath("~/admin/banner/" + FileUpload1.FileName));
                bs.b_image = FileUpload1.FileName;
            }
            else
                bs.b_image = tbimage.Text;
            bs.b_description = tbdescription.Text;
            bs.b_place = ddplace.SelectedValue.ToString();
            bs.isactive = RadioButtonList1.SelectedValue.ToString();
            bs.isdeleted = false;
            bs.SaveRecords();
            Response.Redirect("~/admin/Banner.aspx");
        }
    }
}
